package tools

import (
    "context"
    "fmt"

    "github.com/xuri/excelize/v2"
)

func GetExcelSummary(ctx context.Context, filePath string) (string, error) {
    f, err := excelize.OpenFile(filePath)
    if err != nil {
        return "", fmt.Errorf("open excel failed: %w", err)
    }
    defer f.Close()

    rows, err := f.GetRows("Sheet1")
    if err != nil {
        return "", err
    }

    if len(rows) < 2 {
        return "表格为空。", nil
    }

    header := rows[0]
    summary := "📊 表格指标汇总：\n"
    for i, row := range rows[1:] {
        summary += fmt.Sprintf("- 任务%d: ", i+1)
        for j, cell := range row {
            if j < len(header) {
                summary += fmt.Sprintf("%s=%s; ", header[j], cell)
            }
        }
        summary += "\n"
    }
    return summary, nil
}
